package com.proactive.webapp.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.sql.DataSource;

import com.proactive.webapp.dao.WorksheetCommentReportDAO;
import com.proactive.webapp.entity.WorksheetCommentReport;

public class WorksheetCommentReportDAOImpl implements WorksheetCommentReportDAO{
	private DataSource dataSource;
	private Connection conn = null ;
	private ResultSet rs = null ;
	private PreparedStatement smt = null ;
	
	public void setDataSource(DataSource dataSource) {
		this.dataSource = dataSource;
	}
	
	@Override
	public void insert(WorksheetCommentReport commentReport) {
		// TODO Auto-generated method stub
		String sql = "INSERT INTO worksheet_comment_report(worksheetCommentID, reportReason, "
				+ "reportRemark, memberAccount, createDate) VALUES(?,?,?,?,NOW())";
		try {
			conn = dataSource.getConnection();
			smt = conn.prepareStatement(sql);
			smt.setInt(1, commentReport.getCommentID());
			smt.setString(2, commentReport.getReason());
			smt.setString(3, commentReport.getRemark());
			smt.setString(4, commentReport.getAccount());
			smt.executeUpdate();
			
			smt.close();
 
		} catch (SQLException e) {
			throw new RuntimeException(e);
 
		} finally {
			if (conn != null) {
				try {
					conn.close();
				} catch (SQLException e) {}
			}
		}
	}
}
